home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hiarcmen / bmpmenu.sx next >
Encoding:
Text File  |  1996-05-21  |  4.1 KB  |  115 lines  |  [TEXT/ttxt]

  1. in module BitmapMenuModule
  2.  
  3. --*******************************************************************************
  4. --*        Class name:    MenuButton
  5. --*                                            
  6. --*     Inherits from: TwoDShape and Actuator                                    
  7. --*        Class type: Concrete
  8. --*         Component: User Interface
  9. --*
  10. --*       Description: This is a subclass of TwoDShape and Button which 
  11. --*                    facilitates the creation of hierarchical bitmap menus.
  12. --*                    Top level menus and submenus are created in very much
  13. --*                    the same way.  The only difference lies with the values
  14. --*                    of the supermenu and newMenu keywords.  For top level
  15. --*                    menus, set supermenu to UNDEFINED and newMenu to TRUE.
  16. --*                    For submenus, set supermenu to its parent menu and newMenu
  17. --*                    to FALSE.  To add new items (non menus) to the menu, use
  18. --*                    the addMenuItem method.
  19. --*
  20. --*             Usage: main menubutton -
  21. --*                        mb := new MenuButton supermenu:UNDEFINED \
  22. --*                                              newMenu:TRUE        \
  23. --*                    sub menubutton - 
  24. --*                        smb := new MenuButton supermenu:mb          \
  25. --*                                              newMenu:FALSE         \
  26. --*                    menu items -
  27. --*                        addmenuitem supermenu label authordata activateAction
  28. --*
  29. --*            IVs:    authordata
  30. --*                    activateAction
  31. --*
  32. --*           Methods:    addMenuItem
  33. --*                    init
  34. --*                    
  35. --*    Required files:    reqFiles/button.sx
  36. --*                    
  37. --*             Notes: If the action to be performed is a method, it must be 
  38. --*                    defined as a method of the authordata.
  39. --*                    
  40. --*                    Also refer to textmenu.sx.  Notice the similarities in the
  41. --*                    way the 2 versions of MenuButton are implemented.
  42. --*
  43. --*            Author:    Su Quek - Kaleida Labs, Inc.
  44. --*******************************************************************************
  45. class MenuButton (TwoDShape, Button)
  46. inst vars
  47.     authordata
  48.     activateAction
  49. end                                         
  50.     
  51. --*=============================================================================*
  52. --*       Method name:    addMenuItem
  53. --*             Class:    MenuButton
  54. --*             Usage: addmenuitem self relBMP prsBMP authordata activateAction
  55. --*                        relBMP    - Bitmap object
  56. --*                        prsBMP    - Bitmap object
  57. --*                        authordata    - object
  58. --*                        activateAction    - function 
  59. --*             Notes: If the activateAction is a method, it must be defined as a 
  60. --*                    method of the authordata.
  61. --*-----------------------------------------------------------------------------*
  62. --*       Description: Adds a terminal button (one which does not invoke another
  63. --*                    menu) and sets its authordata and action.  
  64. --*=============================================================================*
  65. method addMenuItem self {class MenuButton} relBMP prsBMP authordata action -> 
  66. (
  67.     local menuItem := new MenuButton supermenu:self \
  68.                                      newMenu:false \
  69.                                      releasedBitmap: relBMP \
  70.                                      pressedBitmap: prsBMP
  71.     menuItem.authordata := authorData
  72.     menuItem.activateAction := action
  73.     
  74.     return menuItem
  75. )
  76.  
  77. --*=============================================================================*
  78. --*       Method name:    afterInit
  79. --*             Class:    MenuButton
  80. --*             Usage: afterInit self [supermenu:<MenuButton>]        
  81. --*                              [newMenu:<Boolean>]
  82. --*                              [placement:<NameClass>] 
  83. --*                                    - (@menuDown, @menuRight, @menuAtPointer)    
  84. --*-----------------------------------------------------------------------------*
  85. --*       Description: Adds the button to its supermenu or creates it's submenu 
  86. --*                    as appropriate.
  87. --*=============================================================================*
  88. method afterInit self {class MenuButton} #rest args #key supermenu:(undefined) \
  89.                                                     newMenu:(true) \
  90.                                                     placement:(@menuDown) ->
  91. (    
  92.     nextmethod self
  93.     
  94.     --*=========================================================================*
  95.     --* Create a submenu for this button
  96.     --*=========================================================================*
  97.     if newMenu do 
  98.     (
  99.         local subMenu := new menu
  100.         subMenu.placement := placement
  101.         self.menu := subMenu
  102.     )
  103.  
  104.     --*=========================================================================*
  105.     --* Add this button to its supermenu
  106.     --*=========================================================================*
  107.     if (supermenu <> undefined) do
  108.         append supermenu.menu self
  109.         
  110.     return self                                  
  111. )
  112.  
  113. "Loaded hiermenu.sx"
  114.  
  115.